package com.zelin.service.impl;

import com.zelin.mapper.BooksMapper;
import com.zelin.pojo.Books;
import com.zelin.pojo.BooksExample;
import com.zelin.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BooksMapper bookMapper;

    @Override
    public List<Books> findAll(int cid) {
        BooksExample booksExample = new BooksExample();
        BooksExample.Criteria criteria = booksExample.createCriteria();
        criteria.andCidEqualTo(cid);
        Collection<Books> books = bookMapper.selectByExample(booksExample);
        return (List<Books>) books;
    }

    @Override
    public void add(Books books) {
        bookMapper.insertSelective(books);
    }

    @Override
    public void up(Books books) {
        bookMapper.updateByPrimaryKey(books);
    }

    @Override
    public void del(int bid) {
        bookMapper.deleteByPrimaryKey(bid);
    }
}
